package cn.edu.ecut.controller;

import cn.edu.ecut.entity.Topic;
import cn.edu.ecut.service.TopicService;
import com.mozicoding.web.context.RequestHolder;
import com.mozicoding.web.support.Controller;
import com.mozicoding.web.support.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller( path = "/topic" )
public class TopicController {

    private TopicService topicService = new TopicService();

    @RequestMapping( path = "/page/list" )
    public String listPage(){
        // 获得当前请求对象
        HttpServletRequest request = RequestHolder.getCurrentRequest();
        // 使用 TopicService 提供的支持查询指定模块中的所有题目 (这里的模块暂时是写死的)
        List<Topic> topics = topicService.loadTopics( 4 );
        // 将查询得到的Topic列表设置到请求对象中并指定属性名称为 topicList
        request.setAttribute( "topicList" , topics );
        return "/WEB-INF/assets/topic-list.html" ;
    }

}
